﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>

<body>

    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-form-item">
                <button type="button" class="layui-btn layui-bg-red" id="searchBtn" onclick="Show()">删除</button>

                <button type="button" class="layui-btn layui-bg-red" onclick="AddInput()" lay-on="test-iframe-curl">新增</button>
            </div>


        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">初期日期</label>
            <div class="layui-inline">
                <input type="date" id="openingdate" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">

            </div>&nbsp&nbsp&nbsp&nbsp&nbsp
            <label>单据号  -- --</label> &nbsp&nbsp&nbsp&nbsp&nbsp
            <label>流水号  -- --</label>
        </div>





        <table id="test" class="layui-table">
            <thead>
                <tr>
                    <td>耳号</td>
                    <td>栋舍</td>
                    <td>栏位</td>
                    <td>只数</td>
                    <td>公斤</td>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>
                        <select id="earBugles">
                            <option value="">请选择</option>
                        </select>
                    </td>
                    <td>
                        <select id="cottageId" lay-filter="provincet">
                            <option value="">请选择</option>
                        </select>
                    </td>
                    <td>
                        <select id="field" lay-filter="city">
                            <option value="">请选择</option>
                        </select>
                    </td>
                    <td><input type="text" id="elements" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input"></td>
                    <td><input type="text" id="weight" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input"></td>
                </tr>
            </tbody>
        </table>
        <div class="layui-form">
            <label class="layui-form-label">备注</label>
            <textarea id="remark" placeholder="请输入" class="layui-textarea"></textarea>

        </div>
        @* /Initial/AddInitialIndex *@

    </form>



    <script>
        var form = layui.form;
        var $ = layui.jquery;

        $(function () {
            bangsheng();
            bangsheng1();
        })

        //栋舍
        function bangsheng() {
            $.ajax({
                url: "http://localhost:5123/api/Cottage/CottageSecondaryQuery",
                data: JSON.stringify({}),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    console.log(res)
                    $.each(res.data, function () {
                        $("#cottageId").append(`<option value="${this.cottageId}">${this.cottageName}</option>`);
                    })
                    form.render('select'); // 重新渲染下拉框
                }
            })
        }

        form.on('select(provincet)', function (data) {
            provincetId1 = data.value;
            console.log(provincetId1)
            $("#field").empty();
            $("#field").append('<option value="">请选择</option>');
            bangshi()

        });
        // form.on('select(city)', function (data) {
        //     cityid = data.value;
        //     console.log(provincetId1)
        //     $("#countyId").empty();
        //     $("#countyId").append('<option value="">请选择</option>');
        //     bangxian();

        // });


        //栏位
        function bangshi() {
            var cottageId = $("#cottageId").val();
            $.ajax({
                url: "http://localhost:5123/api/Field/GetFieldCottage",
                data: JSON.stringify({ cottageId: cottageId }),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    console.log(res.data)

                    $.each(res.data, function () {
                        $("#field").append(`<option value="${this.fieldId}">${this.fieldName}</option>`);
                    })
                    form.render('select'); // 重新渲染下拉框
                }

            })
        }

        //绑定耳号
        function bangsheng1() {

            $.ajax({
                url: "http://localhost:5269/api/SheepArchive/SheepEarBuglesPrhQuery",
                data: JSON.stringify({}),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    console.log(res)
                    $.each(res.data, function () {
                        $("#earBugles").append(`<option value="${this.recordAuricle}">${this.recordAuricle}</option>`);
                    })
                    form.render('select'); // 重新渲染下拉框

                }

            })
        }





        function AddInput() {
            var data = {
                document: $("#document").val(),
                openingdate: $("#openingdate").val(),
                auricle: $("#earBugles").val(),
                cottageId: $("#cottageId").val(),
                field: $("#field").val(),
                weight: $("#weight").val(),
                remark: $("#remark").val(),
                elements: $("#elements").val(),
                seasonType: 0
            }
            $.ajax({
                url: "http://localhost:5123/api/Startofseason/CreateStartofseason",
                type: "post",
                data: JSON.stringify(data),
                dataType: "json",
                contentType: "application/json",
                success: d => {
                    if (d == 0) {
                        layer.msg('保存失败');
                    }
                    else {
                        layer.msg('保存成功');
                        if (data.seasonType == 0) {
                            location.href = "/Initial/InitialIndex";
                        }
                        else if (data.seasonType == 1) {
                            location.href = "/Initial/SpermatophoreIndex";
                        }
                        else {
                            location.href = "/Initial/ProgenyIndex";
                        }
                    }
                }
            })



        }


    </script>


</body>

</html>